package com.zrkj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zrkj.entity.TSysResource;
import com.zrkj.entity.vo.Result;
import com.zrkj.service.ITSysResourceService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : 国良
 * @className : TSysResourceController
 * @package: com.ha.controller
 * @description : 资源表 前端控制器
 * @date :  2021-05-14
 */
@RestController
@RequestMapping(value = "/tSysResource")
@Api(tags = "资源表")
public class TSysResourceController {
    private final ITSysResourceService itSysResourceService;

    public TSysResourceController(ITSysResourceService itSysResourceService) {
        this.itSysResourceService = itSysResourceService;
    }

    /**
     * 添加
     *
     * @param tSysResource
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody TSysResource tSysResource) {
        return itSysResourceService.add(tSysResource);
    }

    /**
     * 更新
     *
     * @param tSysResource
     * @return
     */
    @PutMapping(value = "/update")
    public Result<Boolean> update(@RequestBody TSysResource tSysResource) {
        return itSysResourceService.update(tSysResource);
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/delete")
    public Result<Boolean> delete(@RequestParam(value = "ids") String ids) {
        String[] idsArray = ids.split(",");
        List<Long> idList = new ArrayList<>();
        for (String id : idsArray) {
            idList.add(Long.valueOf(id));
        }
        return itSysResourceService.delete(idList);
    }

    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/getById/{id}")
    public Result<TSysResource> getById(@PathVariable(value = "id") Long id) {
        return itSysResourceService.getById(id);
    }

    /**
     * 查询列表
     *
     * @param tSysResource
     * @return
     */
    @PostMapping(value = "/queryList")
    public Result<List<TSysResource>> queryList(@RequestBody TSysResource tSysResource) {
        return itSysResourceService.queryList(tSysResource);
    }

    @PostMapping(value = "/queryPageList")
    public Result<IPage<TSysResource>> queryPageList(@RequestBody TSysResource data) {
        return itSysResourceService.queryPageList(data);
    }

    @PostMapping(value = "/getAllReasource")
    public Result getAllReasource(){
        return itSysResourceService.getAllReasource();
    }
}
